package cn.tedu.spring.life;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class User {
    private String username;

    public User() {
        System.out.println("1:实例化阶段,调用无参构造方法;");
    }

    @Value("只手遮天")
    public void setUsername(String username) {
        this.username = username;
        System.out.println("2:属性赋值阶段,调用set方法;");
    }

    @PostConstruct
    public void init(){
        System.out.println("3:初始化阶段,初始化时执行此方法");
    }

    @PreDestroy
    public void destroy(){
        System.out.println("5:销毁之前,执行的方法");
    }

    public String getUsername() {
        return username;
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                '}';
    }
}










